﻿<template>
    <full-screen-dialog
        title="付款信息录入"
        v-model="visible"
        :width="600"
        destroy-on-close
        :close-on-click-modal="false"
        @closed="$emit('closed')"
    >
        <el-form
            :model="entityObj"
            :rules="rules"
            :disabled="mode == 'Show'"
            ref="dialogForm"
            label-width="100px"
        >

           
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="付款日期" prop="tradeTime">
                        <el-date-picker
                            style="width: 100%"
                            v-model="entityObj.tradeTime"
                            type="datetime"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                           
                        />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="付款金额" prop="tradeAmount">
                        <el-input-number v-model="entityObj.tradeAmount" type="text" style="width: 100%"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="交易单号">
                        <el-input v-model="entityObj.tradeNo" type="text"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="付款方式" prop="payType">
                        
                        <el-select placeholder="---请选择付款方式---" v-model="entityObj.payType" style="width: 100%">
                            <el-option v-for="item in optionsPayType" :key="item.value" :label="item.label" :value="item.value" />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
          
            <el-row v-if="entityObj.payType==0">
                <el-col :span="22">
                    <el-form-item label-width="120px" label="银行账号">
                        <el-select placeholder="---请选择付款账号---" v-model="entityObj.bankAccount" style="width: 100%">
                            <el-option v-for="item in optionsBankAccounts" :key="item.bankAccount" :label="item.bankAccount" :value="item" />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row v-if="entityObj.payType==0">
                <el-col :span="22">
                    <el-form-item label-width="120px" label="公司名称/姓名">
                        <el-input v-model="entityObj.bankAccount.name" type="text" :disabled="true"/>
                    </el-form-item>
                    <el-form-item label-width="120px" label="开户行">
                        <el-input v-model="entityObj.bankAccount.openBankName" type="text" :disabled="true"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row v-if="entityObj.payType==2">
                <el-col :span="22">
                    <el-form-item label-width="120px" label="电子账号">
                        <el-input v-model="entityObj.eBankInfo.bankAccount" type="text"  :disabled="true"/>
                    </el-form-item>
                    <el-form-item label-width="120px" label="电子余额">
                        <el-input v-model="entityObj.eBankInfo.bankBalance" type="text"  :disabled="true"/>
                    </el-form-item>
                </el-col>
            </el-row>
          
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="付款银行">
                        <el-select placeholder="---请选择付款方式---" v-model="entityObj.payBankCode" style="width: 100%">
                            <el-option v-for="item in optionsBank" :key="item.value" :label="item.label" :value="item.value" />
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
           
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="付款账号">
                        <el-input v-model="entityObj.payBankAccount" type="text"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="录单人">
                        <el-input v-model="entityObj.createName" type="text" disabled/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="录单日期">
                        <el-input v-model="entityObj.createTime" type="text" disabled/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="备注">
                        <el-input v-model="entityObj.remarks" type="textarea" :rows="4" />
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <el-button @click="visible = false">取 消</el-button>
            <el-button
                v-if="mode != 'show'"
                type="primary"
                :loading="isSaveing"
                @click="submit()"
            >确 定</el-button>
        </template>
    
    </full-screen-dialog>
</template>

<script>
import tool from "@/utils/tool";
export default {
    emits: ["success", "closed"],
    data() {
        return {
            mode: "Add",
            entityObj: {
                bankAccount:{
                    openBankName:"",
                    name:"",
                }
            },
            visible: false,
            isSaveing: false,
            needSaveFlag: false,
            //验证规则
            rules: {
                tradeTime: [
                    { required: true, type: "string", message: "请填写付款时间" },
                ],
                tradeAmount: [
                    { required: true, type: "number", message: "请填写付款金额" },
                ],
                payType: [
                    { required: true, type: "number", message: "请填写付款方式" },
                ],
            },
            optionsPayType:[],//付款方式
            optionsBank:[],//银行
            optionsBankAccounts:[],//银行账户
            
        };
    },
   
 
    methods: {
        //显示=
        open(mode = "Add") {
            this.mode = mode;
            this.visible = true;
            return this;
        },
        async setData(data){
             this.entityObj.supplierId=data.supplierId;
             this.entityObj.billId=data.billId;
             this.entityObj.eBankInfo=data.eBankInfo;
             this.optionsBankAccounts=data.bankInfos;
		}, 
     
        //表单提交方法
        submit() {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    this.isSaveing = true;
                    const data={ ...this.entityObj}
                    console.log("data",data)
                    try {
                        var returnValue =await this.$API.auth.PostProcessApi.post("billInfo/addPay",data);
                        if (returnValue.status == 200) {
                            this.$message.success("操作成功");
                            this.$emit("fatherMethod");
                            this.isSaveing = false;
                            this.visible = false;
                        } else {
                            this.$message.error("操作失败:" + returnValue.msg);
                        }
                    } catch (error) {
                        this.loading = false;
                        return false;
                    }
                }
            });
        },
        async initOptions() {
                try {
                    var returnValue = await this.$API.auth.PostProcessApi.post(
                        "base-dictionary/options",
                        { Codes: ["PayType"] }
                    );
                    if (returnValue.status == 200) {
                        this.optionsPayType =returnValue.response.find(p=>p.code=="PayType").optionsDetails;
                    } else {
                        this.$message.error("操作失败:" + returnValue.msg);
                    }
                } catch (error) {
                    this.loading = false;
                    return false;
                }

                try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "base-dictionary/dic-options",
                    { ParentBaseDictionaryCodes: ["003"] }
                );
                if (returnValue.status == 200) {
                    this.optionsBank = returnValue.response.find(
                        (p) => p.code == "003"
                    ).optionsDetails;
                    console.log("optionsBank",this.optionsBank);
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
          

        }
       
    },
    async mounted() {
        await this.initOptions();
        this.entityObj.tradeTime=tool.formatDate(new Date());
        this.entityObj.createId= tool.data.get("USER_INFO").AccountId;
        this.entityObj.createName = tool.data.get("USER_INFO").Name;
        this.entityObj.createTime = tool.formatDate(new Date());

    },
};
</script>
